// chalk用于打印不同颜色的内容
// npm i chalk@4.1.2
const chalk = require("chalk");
console.log(chalk.red("********** hello world **********"));

const path = require("path");
// path.resolve合并路径
console.log(path.resolve(process.cwd()));
console.log(path.resolve(process.cwd(), "package.json"));

// 检测文件是否存在
const fs = require("fs");
console.log(fs.existsSync(path.resolve(process.cwd(), "package.json")));

// 提供选择模块。传入数组即可。
const prompts = require("prompts");
const presetPrompt = {
  name: "cssType",
  type: "select",
  message: "请选择需要初始化的css工具类型",
  choices: [
    { title: "less", value: "less" },
    { title: "scss", value: "scss" },
  ],
};

const start = async () => {
  const promptOptions = await prompts([presetPrompt], {
    onCancel: () => {
      console.log(chalk.yellow("操作已取消"));
      canceled = true;
    },
  });
  console.log(promptOptions, "promptOptions");
  console.log(chalk.red("********** end **********"));
};

start();

// spinner 作用loading效果
const Spinner = require("cli-spinner").Spinner;
const spinner = new Spinner(chalk.yellow("spinner starting") + " %s");
spinner.setSpinnerString("|/-\\");
spinner.start();
setTimeout(() => {
  spinner.stop(true);
}, 1000);
